package com.ideafactory.client.ybservice.ybviewpager;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;

import com.ideafactory.client.ybselfservice.R;

import org.xutils.x;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by LiuShao on 2016/5/24.
 */
public class GoodsPagerSuccessPager extends GoodsBasePager{

    public GoodsPagerSuccessPager(Context context) {
        super(context);
    }

    private int conunt = 8;//倒计时5s
    private Timer timer;

    @Override
    public View initView() {
        View view = View.inflate(context, R.layout.fragment_paysuccess,null);
        x.view().inject(this, view);
        return view;
    }

    private Handler handler ;

    @Override
    public void initViewBuind() {
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        if (msg.arg1 == 0) {
                            Log.e("支付成功跳转","--------------");
                            onPagerChange.changePositon(GOODS_PAY_SCUESS_INT,MAIN_FRAGMENT);
                        }
                        break;
                }
            }
        };
    }

    @Override
    public void initData(int fromPager) {
        conunt = 8;

        if (timer == null) {
            timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    conunt--;
                    if(conunt == 0){
                        Message msg = new Message();
                        msg.what = 1;
                        msg.arg1 = conunt;
                        Log.e("支付成功时间结束", "--------------");
                        handler.sendMessage(msg);
                        timer.cancel();
                        timer=null;
                    }
                }
            }, 500, 1000);
        }
    }

}
